<?php
//fetch the passed request
$request = $_SERVER['QUERY_STRING'];

//parse the page request and other GET variables
$parsed = explode('&' , $request);

//the page is the first element
$page = array_shift($parsed);
$variable = "oauth_token";
if(preg_match("/{$variable}/i", $page)){
    //var_dump($_GET);
    //die();
    $twitter_url = SITE_ROOT."?twitter&oauth_token=".$_GET['oauth_token']."&oauth_verifier=".$_GET['oauth_verifier'];
    //echo $url;
    //die();
    echo '<meta http-equiv="Refresh" content="0;url='.$twitter_url.'">';
}
//var_dump($page);
//echo $page;
//the rest of the array are get statements, parse them out.
/**$getVars = array();
foreach ($parsed as $argument)
{
	//split GET vars along '=' symbol to separate variable, values
	list($variable , $value) = explode('=' , $argument);
	$getVars[$variable] = urldecode($value);
}**/

//compute the path to the file
if(($page == "")){
    $page = "index"; 
}
$page = str_replace("=", "", $page);
$target = WEB_ROOT_FOLDER . $page . '/controllers/' . $page . '.php';
//echo $target;
//get target
try {
	if (file_exists($target))
	{
            
		include_once($target);
		//modify page to fit naming convention
		$class = ucfirst($page) . '_Controller_'.  ucfirst($page);

                
		//instantiate the appropriate class
		if (class_exists($class))
		{
                    //echo $class;
			$controller = new $class;
		}
		else
		{
			//did we name our class correctly?
			//throw new Exception(CLASS_DOES_NOT_EXISTS."<strong>".$class."</strong>!");
                    $controller = new Index_Controller_Index;
		}
	}
	else
	{
		//can't find the file in 'controllers'!
		//throw new Exception(CAN_NOT_LOAD_FILE."<strong>".$target."</strong>.".FILE_DOES_NOT_EXISTS);
               echo '<meta http-equiv="Refresh" content="0;url='.SITE_ROOT.'">';
	}
}
catch (Exception $exception){
	echo $exception->getMessage();
}

